<template>
  <div>
    <HeaderYi
      @searchfn="searchfns"
      :records="records"
      @isShow="isShowfn"
      @id="index = $event"
    ></HeaderYi>
    <MainYi
      :records="records[index]"
      :isShow="isShow"
      @close="isShowfn"
    ></MainYi>
  </div>
</template>

<script>
import HeaderYi from './components/HeaderYi.vue'
import MainYi from './components/MainYi.vue'
export default {
  data() {
    return {
      index: '',
      isShow: false,
      records: [
        {
          date: '2022-01-01',
          doctor: '张三',
          diagnosis: '感冒',
          prescription: '感冒药'
        },
        {
          date: '2022-02-01',
          doctor: '李四',
          diagnosis: '头疼',
          prescription: '止疼药'
        },
        {
          date: '2022-03-01',
          doctor: '王五',
          diagnosis: '腰痛',
          prescription: '止痛贴'
        }
      ]
    }
  },
  methods: {
    isShowfn(val) {
      this.isShow = val
    },
    searchfns(value) {
      for (let i = 0; i < this.records.length; i++) {
        if (
          this.records[i].date === value ||
          this.records[i].doctor === value ||
          this.records[i].prescription === value ||
          this.records[i].diagnosis === value
        ) {
          this.records = this.records.filter((item, index) => index === i)
        }
      }
      // if (value === this.records.doctor) {
      // }
      // return (this.records = this.records[2])
    }
  },
  components: {
    HeaderYi,
    MainYi
  }
}
</script>

<style></style>
